/**
 * @description service get-cdn-url
 *
 * @author xiaomi
 */

const path = require('path');
const pkgs = require('../../package.json');

const CDN_URL = process.env.CDN_URL || '/';
const appName = pkgs.projectName || pkgs.name || 'x-app';

module.exports = (moduleName = '', uri = '') => {
    const IS_PROD = process.env.NODE_ENV === 'production';

    let url = IS_PROD ? CDN_URL : ('/' + path.basename(CDN_URL));

    url += url.slice(-1) === '/' ? '' : '/';
    // url += `${appName}/`;

    // if(moduleName) {
    //     url += `${moduleName}/`;
    // }

    if(uri) {
        url += url.slice(-1) === '/' ? '' : '/';
        url += uri;
    }

    return url;
};
